<include file="Common:header"/>

<body>
	<div class="top-wrap">
		<div class="title-bg">我的发布</div>
	</div>
	<div class="main-wrap" style="padding-top:10px;">
	<if condition = "!empty($article_list)">
		<foreach name="article_list" item="row">
			<div class="article-list-box">
			<div class="article-list-time"><{:date("Y年m月d日 H:i:s",$row['createtime'])}>&nbsp;&nbsp;(阅读数：<{$row['read']}>)</div>
			<div class="article-list-content">
				<{$row['title']}>
			</div>
			<div class="btn-right">
				<a href="javascript:void(0)" onclick="share_click($(this))" data-url="<{:U('Home/Publish/article_detail',array('aid'=>$row['id']),true,true)}>" class="btn_l">分享</a><a href="javascript:void(0)" data-aid="<{$row['id']}>" onclick="delete_article(this)" class="btn_l">删除</a><a href="<{:U('Home/Article/article_detail',array('aid'=>$row['id']))}>" class="btn_l">修改</a>
			</div>
		</div>
		<div class="grey-hr mg-b-5"></div>
		</foreach>
	<else />
		<div class="grey-hr mg-b-15" style="text-align:center;font-size:16px">～暂无数据～</div>
	</if>
		<div id="loadding" style="text-align: center; display: none;"><img src="__PUBLIC__/js/layer/skin/default/loading-0.gif" /></div>
	</div><!-- end:main-wrap -->
	<input type="hidden" id="page" value="1">

	<!-- 百度分享按钮 -->
	<div id="share_box" class="bdsharebuttonbox share_article_position" data-tag="share_1" id="share_article">
		<a class="bds_qzone" data-cmd="qzone" style="background-position:0px;background-image:url('/Public/img/qqkj.png');background-size:100%;height:36px;width:36px"></a>
		<a class="bds_tsina" data-cmd="tsina" style="background-position:0px;background-image:url('/Public/img/xlwb.png');background-size:100%;height:36px;width:36px"></a>
		<a class="bds_renren" data-cmd="renren" style="background-position:0px;background-image:url('/Public/img/renren.png');background-size:100%;height:36px;width:36px"></a>
		<a class="bds_tqq" data-cmd="tqq" style="background-position:0px;background-image:url('/Public/img/txwb.png');background-size:100%;height:36px;width:36px"></a>
		<a class="bds_weixin" data-cmd="weixin" style="background-position:0px;background-image:url('/Public/img/weixintb.png');background-size:100%;height:36px;width:36px"></a>
	</div>
	
	<include file="Common:menu"/>

</body>
</html>
<script>
$(function(){
	$(window).scroll(function () {
		$('#share_box').hide();
		if($(window).scrollTop()>=($(document).height()-$(window).height())){
			ajax_article();
		}
	});
});


//加载文章
function ajax_article(){
	var loadObj = $('#loadding');
	var page = $('#page').val();
	if(page == '-1'){
		return false;
	}
	loadObj.show();
	$.ajax({
		type: "POST",
		url: "<{:U('Home/Article/article_list')}>",
		data: "page="+page,
		dataType:'json',
		success: function(msg){
			if(msg.status == '1'){
				var html = '';
				for(var i  in  msg.data){
					html +='<div class="article-list-box">';
					html +='<div class="article-list-time">'+msg.data[i].createtime+'&nbsp;&nbsp;(阅读数：'+msg.data[i].read+')</div>';
					html +='<div class="article-list-content">'+msg.data[i].title+'</div>';
					html +='<div class="btn-right">';
					html +='<a href="javascript:void(0)" data-url="'+msg.data[i].url+'" onclick="share_click($(this))" class="btn_l">分享</a>';
					html +='<a href="javascript:void(0)" data-aid="'+msg.data[i].id+'" onclick="delete_article(this)"  class="btn_l">删除</a>';
					html +='<a href="/index.php/Home/Article/article_detail/aid/'+msg.data[i].id+'.html"  class="btn_l">修改</a>';
					html +='</div></div><div class="grey-hr mg-b-15"></div>';
				}
				page = parseInt(page) + 1;
				$('#page').val(page);
				$('#loadding').before(html);
				loadObj.hide();
			}else{
				$('#page').val('-1');
				loadObj.hide();
			}
		}
	});
}

//删除文章
function delete_article(obj){
	var aid = $(obj).attr('data-aid');
		
	layer.open({
		content: '您确定删除文章吗？',
		btn: ['确认', '取消'],
		shadeClose: false,
		yes: function(){
			$.ajax({
				type: "POST",
				url: "<{:U('Home/Article/article_delete')}>",
				data: "aid="+aid,
				success: function(msg){
					if(msg.status == '-1' ){
						layer.open({
							content:msg.msg
						});
					}else{
						layer.open({
							content:'文章删除成功',
							btn: ['确认'],
							yes:function(){
							   window.location.reload();
							}
						});
					}
				}
			});
		}
	});	
}

// 定义全局URL 用于分享链接
var shareUrl = '';

//点击分享文章
function share_click(obj){
	shareUrl = obj.attr('data-url');
	var shareBox = $('#share_box');
	var objPos = obj.offset();
	var top = objPos.top + obj.height();
	var left = objPos.left + obj.innerWidth()/2 - shareBox.innerWidth()/2;

	shareBox.css('top',top);
	shareBox.css('left',left);

	if (shareBox.is(':hidden')) {
		shareBox.show();
	}else{
		shareBox.hide();
	}
}

// 变更对应的 分享文章链接
function setShareUrl(cmd, config)
{
	// console.log(cmd);
	if (cmd == 'weixin' && <?php if (is_weixin()) { echo 'true';}else{ echo 'false';} ?>) {
		// 设置微信分享提示
		document.cookie = 'weixin_share = 1; path=/';
		window.location.href = shareUrl;
	};
	config.bdUrl = shareUrl;
	return config;
}

// 百度分享配置
window._bd_share_config = {
	common : {
		onBeforeClick: setShareUrl,
		bdText : '',
		bdDesc : '',
		bdUrl : '<{:U('Main/Index/index',array('aid'=>1),true,true)}>', 
		bdPic : ''
	},
	share : [{
		"bdSize" : 32
	}],
	selectShare : [{
		"bdselectMiniList" : ['qzone','tqq','kaixin001','bdxc','tqf']
	}]
}
with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?cdnversion='+~(-new Date()/36e5)];

$(document).click(function(){
	$("#share_box").hide();
})
$("#share_box").click(function(event){
event.stopPropagation();

});
$(".btn-right a").click(function(event){
event.stopPropagation();
});
</script>
